
window.onload = function()
{
    setFromCookie();
	//setTimeout("setFromCookie()",200);
}

function headerMouseOver(td)
{
	td.style.backgroundColor='#999999';
	td.style.cursor='hand';
}
function headerMouseOut(td)
{
	td.style.backgroundColor='#C1C1C1';
	//td.style.backgroundColor='#42788c';
}

function headerMousePress(id,td)
{
	ioSwitch(id);
}

function setFromCookie()
{
	if (document.getElementsByTagName) {
		var nl = document.getElementsByTagName('div');
		var l = nl.length;
		for (var i = 0; i<l; i++){
			var node = nl.item(i);
			if (node.getAttribute('name') == 'menuItem') {
				var id = node.id;
				var val = getCookie(id);
				if(val == "collapsed"){
					collapse(id,true);
				} else if (val == 'expanded'){
					expand(id,true);
				} else {
					if(node.getAttribute('init') == 1){
						expand(id,true);
					} else {
						collapse(id,true);
					}
				}	
			}
		}
	}
}	

function setToDefault()
{
	if (document.getElementsByTagName) {
		var nl = document.getElementsByTagName('div');
		var l = nl.length;
		for (var i = 0; i<l; i++){
			var node = nl.item(i);
			if (node.getAttribute('name') == 'menuItem') {
				if(node.getAttribute('init') == 1){
					expand(node.id);
				} else {
					collapse(node.id);
				}	
			}
		}
	}
}

img_expanded  = 'graftemplate/bolo.gif';
img_collapsed = 'graftemplate/boloon.gif';

function expand(ioNode,cook) {
	ioWedge = "i" + ioNode.substr(1);
	ioButton = "b" + ioNode.substr(1);
	
	if (document.getElementById && document.getElementById(ioNode) != null) {
		if(!cook)setCookie(ioNode, "expanded", getCTime(), '/', "www.educaplus.org", '');
	//	document.getElementById(ioButton).style.borderBottom="0px solid #003366";
		document.getElementById(ioWedge).src=img_collapsed;
		document.getElementById(ioWedge).title='collapse';
		document.getElementById(ioNode).className='expanded';
	}
}

function collapse(ioNode,cook) {
	ioWedge = "i" + ioNode.substr(1);
	ioButton = "b" + ioNode.substr(1);
	
	if (document.getElementById && document.getElementById(ioNode) !=  null) {
		if(!cook)setCookie(ioNode, "collapsed", getCTime(), '/', "www.educaplus.org", '');
	//	document.getElementById(ioButton).style.borderBottom="1px solid #003366";
		document.getElementById(ioWedge).src=img_expanded;
		document.getElementById(ioWedge).title='expand';
		document.getElementById(ioNode).className='collapsed';
	}
}

function ioSwitch(ioNode) {

	if (document.getElementById && document.getElementById(ioNode) !=  null) {
		nodeState = document.getElementById(ioNode).className;
	}

    if (nodeState == 'collapsed') {
		expand(ioNode);
		return 1;
	}

	else {
		collapse(ioNode);
		return 0;
	}
}

function expandAll(divName) 
{
	if (document.getElementsByTagName) {
		var nl = document.getElementsByTagName('div');
		var l = nl.length;
		for (var i=0; i<l;i++) {
			var node = nl.item(i);
			if (node.getAttribute('name') == divName) {
				expand(node.id);	
			}
		}
	}
}

function collapseAll(divName) 
{
	if (document.getElementsByTagName) {
		var nl = document.getElementsByTagName('div');
		var l = nl.length;
		for (var i=0; i<l;i++) {
			var node = nl.item(i);
			if (node.getAttribute('name') == divName) {
				collapse(node.id);	
			}
		}
	}
}



// Cookie functions

function setCookie (name, value, expires, path, domain, secure) 
{
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) 
{
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
	var value = unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
    return value;
}


function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}


function getCTime()
{
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	return now;
}